/*
 * Copyright Thoughtworks, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.thoughtworks.go.apiv1.i18n;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * I18n 服务，负责管理翻译数据的业务逻辑
 */
@Service
public class I18nService {
    private static final Logger LOGGER = LoggerFactory.getLogger(I18nService.class);

    /**
     * 根据页面类型获取翻译数据
     */
    public I18nData getTranslationsByPage(String locale, String page) {
        LOGGER.debug("Loading translations for page: {} and locale: {}", page, locale);

        try {
            I18nData pageTranslations = TranslationLoader.loadFromFile(page, locale);

            LOGGER.debug("Successfully loaded translations for page {}: zh-CN={}, en={}",
                page, pageTranslations.getZhCN().size(), pageTranslations.getEn().size());

            return pageTranslations;
        } catch (Exception e) {
            LOGGER.error("Failed to load translations for page {}: {}", page, e.getMessage(), e);
            throw new RuntimeException("Failed to load translations for page: " + page, e);
        }
    }
}
